<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="发起机构" prop="createOrgId">
        <treeselect :default-expand-level="1"  v-model="queryParams.createOrgId" :options="deptOptions" size="small" placeholder="请选择机构"  :show-count="true" style="width:300px;"/>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="taskList" style="min-height: 260px;">
      <el-table-column label="编号" align="center" prop="instanceId" width="60"/>
      <el-table-column label="流程名称"  prop="flowName" :show-overflow-tooltip="true"/>
      <el-table-column label="发起机构"  prop="createOrgId" :formatter="createOrgFormat" :show-overflow-tooltip="true" />
      <el-table-column label="发起人员" align="center" prop="createBy" width="100"/>
      <el-table-column label="发起时间" align="center" prop="startTime" width="140">
      </el-table-column>
      <el-table-column label="签批步骤" align="center" prop="nodeName" width="80" :show-overflow-tooltip="true"/>
      <el-table-column label="任务状态" align="center" prop="taskStatusOpt" :formatter="taskStatusOptFormat" width="60"/>
      <el-table-column label="签收人员" align="center" prop="signUser" width="100"/>
      <el-table-column label="签批结果" align="center" prop="finishFlagOpt" :formatter="finishFlagOptFormat" width="60"/>
      <el-table-column label="完成时间" align="center" prop="finishTime" width="140">
      </el-table-column>
      <el-table-column label="操作" align="center" width="60">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handlePreview(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <PurchasePreview v-if="businessType=='procurementChemicals'" ref="preview" @refresh="getList" edit></PurchasePreview>
    <ReceiptPreview v-if="businessType=='materialRepairApplication'" ref="preview" @refresh="getList"></ReceiptPreview>
    <ProjectDetails v-if="businessType=='projectCreationApplication'" ref="preview" @refresh="getList"></ProjectDetails>
    <OccupationPreview v-if="businessType=='applicationChemicals'"  ref="preview" @refresh="getList"></OccupationPreview>
    <ReservationDetail v-if="businessType=='labReservationApplication'" ref="preview" @refresh="getList"></ReservationDetail>
    <SafetyPreview v-if="businessType=='safetyCheck'" ref="preview" @refresh="getList"></SafetyPreview>
    <DeclarationFilingDetail v-if="businessType=='labDeclarationFilingApplication'" ref="preview" @refresh="getList"></DeclarationFilingDetail>
    <EvalutionDetail v-if="businessType=='labEvalution'" ref="preview" @refresh="getList"></EvalutionDetail>
    <TaskPreview v-if="businessType=='safetyCheckTask'" ref="preview" @refresh="getList"></TaskPreview>
  </div>
</template>

<script>
  import {
    doneList,
  } from "@/api/labdata/flowTask";
  import { treeselect,getTreeLabel } from "@/api/labdata/orgnization";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import PurchasePreview from "@/views/labdanger/dangerComps/purchasePreview.vue";
  import ReceiptPreview from "@/views/labbase/receipt_form/receipt_preview.vue"
  import ProjectDetails from "@/views/labbase/project_creation/projectDetail.vue";
  import OccupationPreview from "@/views/labdanger/dangerComps/occupationPreview.vue";
  import ReservationDetail from "@/views/labdata/reservation/reservationDetail.vue";
  import SafetyPreview from "@/views/labsafety/labsafetyForm/view/viewDialog.vue";
  import TaskPreview from "@/views/labsafety/labsafetyTask/view/viewDialog.vue";
  import DeclarationFilingDetail from "@/views/labdata/declarationFiling/declarationFilingDetail.vue";
  import EvalutionDetail from "@/views/evalution/labEvalution/details.vue";
  export default {
    name: "DoneTask",
    components: {
      PurchasePreview,Treeselect,ReceiptPreview,ProjectDetails,OccupationPreview,
      ReservationDetail,SafetyPreview,DeclarationFilingDetail,EvalutionDetail,TaskPreview
    },
    data() {
      return {
        // 部门树选项
        deptOptions: [],
        // 遮罩层
        loading: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 流程任务表格数据
        taskList: [],
        // 任务状态字典
        taskStatusOptOptions: [],
        // 办理结果字典
        finishFlagOptOptions: [],
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          createOrgId: null,
          businessTypeOpt: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      };
    },
    props:{
      businessType:String,
    },
    created() {
       this.getTreeselect();
      //console.log('businessTypeOpt='+this.businessType)
      this.getList();
      this.getDicts("taskStatusOpt").then(response => {
        this.taskStatusOptOptions = response.data;
      });
      this.getDicts("finishFlagOpt").then(response => {
        this.finishFlagOptOptions = response.data;
      });
    },
    methods: {
      /** 查询部门下拉树结构 */
      getTreeselect() {
         treeselect().then(response => {
           this.deptOptions = response.data;
         });
       },
      handlePreview(row) {
        this.$refs["preview"].handleUpdate(row);
      },
      /** 查询流程任务列表 */
      getList() {
        this.loading = true;
        this.queryParams.businessTypeOpt = this.businessType;
        doneList(this.queryParams).then(response => {
          this.taskList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 任务状态字典翻译
      taskStatusOptFormat(row, column) {
        return this.selectDictLabel(this.taskStatusOptOptions, row.taskStatusOpt);
      },
      createOrgFormat(row,column){
         return getTreeLabel(this.deptOptions,row.createOrgId);
      },
      // 办理结果字典翻译
      finishFlagOptFormat(row, column) {
        return this.selectDictLabel(this.finishFlagOptOptions, row.finishFlagOpt);
      },
      // 表单重置
      reset() {
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
    }
  };
</script>
